package com.shd.day05;

import java.util.Arrays;
import java.util.OptionalInt;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Created by shanhaodong on 2018/7/28
 */
public class NumericStream {
    public static void main(String[] args) {
        Stream<Integer> stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7});
        Integer reduce = stream.filter(i -> i.intValue() > 3).reduce(0, Integer::sum);
        System.out.println(reduce);

        /*IntStream intStream = stream.mapToInt(Integer::intValue);
        intStream.filter(i->i>3).sum();*/

        Stream<int[]> stream1 = IntStream.rangeClosed(1, 100).boxed().flatMap(a -> IntStream.rangeClosed(a, 100)
                .filter(b -> Math.sqrt(a * a + b * b) % 1 == 0)
                .boxed().map(b -> new int[]{a, b, (int) Math.sqrt(a * a + b * b)}));
        stream1.forEach(t-> System.out.println(t[0]+","+t[1]+","+t[2]));
    }
}
